translator: accept thinking_blocks signatures and fall back to skip_thought_signature_validator for Gemini function calls#2366
Merged
mathetake merged 2 commits intoJul 23, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2366 +/- ##
=======================================
Coverage 84.84% 84.85%
=======================================
Files 154 154
Lines 22408 22419 +11
=======================================
+ Hits 19012 19023 +11
Misses 2239 2239
Partials 1157 1157 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
This is an real issue, and we use gemini3 heavily, and always need workarounds for this. Can someone review this? |
mathetake
reviewed
Jul 22, 2026
| // that doesn't round-trip thinking_blocks). Gemini 3.x rejects function calls in | ||
| // multi-turn requests that are missing a thought_signature, so fall back to | ||
| // Google's documented compatibility escape. | ||
| funcCallPart.ThoughtSignature = []byte(dummyThoughtSignature) |
Member
There was a problem hiding this comment.
this causes allocation. can you declare var whatever = []byte("skip_thought_signature_validator") as a global?
Contributor
Author
There was a problem hiding this comment.
sure, addressed in latest commit, also rebased my fork
a-nych
force-pushed
the
fix/gemini-thought-signature-fallback
branch
from
July 23, 2026 08:25
427249c to
c7e99cc
Compare
… Gemini function calls
Gemini 3.x rejects multi-turn tool-calling requests with HTTP 400 when a
function call is missing a thought_signature. The OpenAI->Gemini request
translator only read signatures from assistant content parts of type
"thinking" and had no fallback when a client (correctly, per the OpenAI
schema) doesn't echo one back.
- Add ThinkingBlocks to ChatCompletionAssistantMessageParam so clients that
round-trip response thinking_blocks (LiteLLM convention) can supply a
signature on requests too.
- In assistantMsgToGeminiParts, fall back to the first non-empty
thinking_blocks signature when no content-part signature is present.
- When no signature is available at all, attach Google's documented
compatibility value ("skip_thought_signature_validator") to the first
functionCall part only, per
https://ai.google.dev/gemini-api/docs/thought-signatures.
Signed-off-by: Adam Nych <adam.nych@univio.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Adam Nych <adam.nych@univio.com>
Signed-off-by: Adam Nych <adam.nych@univio.com>
a-nych
force-pushed
the
fix/gemini-thought-signature-fallback
branch
from
July 23, 2026 08:47
c7e99cc to
7dc8543
Compare
mathetake
approved these changes
Jul 23, 2026
mathetake
enabled auto-merge (squash)
July 23, 2026 08:52
Member
|
/retest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Gemini 3.x requires the thought signature (see [1]) returned with a
functionCallto be echoed back on that part in subsequent requests; otherwise Vertex rejects the request with400 INVALID_ARGUMENT("Function call is missing a thought_signature in functionCall parts"). The OpenAI → GCPVertexAI translator emits the signature in responses asmessage.thinking_blocks[].signature(#1995) but on the request side only reads it from assistantcontentparts of type"thinking"(#1726), and sends nothing when absent. Standard OpenAI-schema clients have no signature field to echo, so every tool round-trip with Gemini 3.x fails.This PR changes
assistantMsgToGeminiPartsto:thinking_blocks[].signature— the same shape the gateway itself emits, so round-tripping the response message now works. Content-part signatures keep priority.skip_thought_signature_validatoron the firstfunctionCallpart when the client echoed no signature at all (matching LiteLLM's behavior). Attached to the first part only, consistent with how Gemini attaches signatures for parallel calls.ChatCompletionAssistantMessageParamgains thethinking_blocksfield to make the request/response contract symmetric.Related Issues/PRs (if applicable)
Fixes #2365
Related PRs: #1726, #1995
Special notes for reviewers (if applicable)
gemini_helper_test.go/TestOpenAIMessagesToGeminiContentsexercised tool calls without a signature and now expect the dummy value — that's the intended new behavior, not weakened assertions.aigw runagainst real Vertex (gemini-3.5-flash,eu): the signature-less round-trip returns 200 with this patch and 400 onmain;thinking_blocksecho returns 200 and carries the real signature; streaming unaffected. Vertex accepts the dummy value (documented compatibility path, so no hard dependency on Google keeping undocumented behavior).1: https://ai.google.dev/gemini-api/docs/thought-signatures